import { defineEventHandler, getQuery } from 'h3';

export default defineEventHandler(async (event) => {
  const query = getQuery(event);

  const stats = {
    overview: {
      totalListings: 156,
      activeListings: 89,
      totalOrders: 1247,
      completedOrders: 892,
      totalTransactionValue: 45_682_300,
      totalUsers: 2456,
      activeUsers: 1834,
    },
    categories: [
      {
        id: 'hotel',
        name: '酒店资源',
        count: 45,
        percentage: 28.8,
        avgPrice: 2_500_000,
        totalValue: 112_500_000,
      },
      {
        id: 'restaurant',
        name: '餐饮资源',
        count: 23,
        percentage: 14.7,
        avgPrice: 45_000,
        totalValue: 1_035_000,
      },
      {
        id: 'software',
        name: '软件服务',
        count: 34,
        percentage: 21.8,
        avgPrice: 35_000,
        totalValue: 1_190_000,
      },
      {
        id: 'service',
        name: '人力服务',
        count: 28,
        percentage: 17.9,
        avgPrice: 120_000,
        totalValue: 3_360_000,
      },
      {
        id: 'other',
        name: '其他资源',
        count: 26,
        percentage: 16.7,
        avgPrice: 68_000,
        totalValue: 1_768_000,
      },
    ],
    resourceTypes: [
      {
        type: 'PHYSICAL',
        name: '物理资源',
        count: 78,
        percentage: 50,
        orders: 567,
        revenue: 25_680_000,
      },
      {
        type: 'DIGITAL',
        name: '数字资源',
        count: 45,
        percentage: 28.8,
        orders: 423,
        revenue: 12_450_000,
      },
      {
        type: 'HUMAN',
        name: '人力资源',
        count: 23,
        percentage: 14.7,
        orders: 156,
        revenue: 5_678_000,
      },
      {
        type: 'SERVICE',
        name: '服务资源',
        count: 10,
        percentage: 6.4,
        orders: 101,
        revenue: 1_874_300,
      },
    ],
    priceRanges: [
      {
        range: '0-1万',
        min: 0,
        max: 10_000,
        count: 34,
        percentage: 21.8,
      },
      {
        range: '1-10万',
        min: 10_000,
        max: 100_000,
        count: 56,
        percentage: 35.9,
      },
      {
        range: '10-100万',
        min: 100_000,
        max: 1_000_000,
        count: 43,
        percentage: 27.6,
      },
      {
        range: '100万以上',
        min: 1_000_000,
        max: Number.POSITIVE_INFINITY,
        count: 23,
        percentage: 14.7,
      },
    ],
    trends: {
      listings: [
        { date: '2024-01-01', count: 120 },
        { date: '2024-01-02', count: 123 },
        { date: '2024-01-03', count: 125 },
        { date: '2024-01-04', count: 128 },
        { date: '2024-01-05', count: 132 },
        { date: '2024-01-06', count: 135 },
        { date: '2024-01-07', count: 139 },
        { date: '2024-01-08', count: 142 },
        { date: '2024-01-09', count: 145 },
        { date: '2024-01-10', count: 148 },
        { date: '2024-01-11', count: 151 },
        { date: '2024-01-12', count: 153 },
        { date: '2024-01-13', count: 155 },
        { date: '2024-01-14', count: 156 },
      ],
      orders: [
        { date: '2024-01-01', count: 1180, amount: 42_150_000 },
        { date: '2024-01-02', count: 1185, amount: 42_280_000 },
        { date: '2024-01-03', count: 1190, amount: 42_450_000 },
        { date: '2024-01-04', count: 1195, amount: 42_680_000 },
        { date: '2024-01-05', count: 1203, amount: 42_950_000 },
        { date: '2024-01-06', count: 1210, amount: 43_280_000 },
        { date: '2024-01-07', count: 1218, amount: 43_650_000 },
        { date: '2024-01-08', count: 1225, amount: 44_020_000 },
        { date: '2024-01-09', count: 1232, amount: 44_380_000 },
        { date: '2024-01-10', count: 1238, amount: 44_720_000 },
        { date: '2024-01-11', count: 1242, amount: 45_050_000 },
        { date: '2024-01-12', count: 1245, amount: 45_320_000 },
        { date: '2024-01-13', count: 1246, amount: 45_520_000 },
        { date: '2024-01-14', count: 1247, amount: 45_682_300 },
      ],
    },
    topSellers: [
      {
        id: 'seller_1',
        name: '酒店管理集团',
        avatar: '/images/sellers/seller-1.jpg',
        totalListings: 23,
        totalOrders: 156,
        totalRevenue: 12_560_000,
        rating: 4.8,
        verified: true,
      },
      {
        id: 'seller_2',
        name: '酒店科技公司',
        avatar: '/images/sellers/seller-2.jpg',
        totalListings: 15,
        totalOrders: 89,
        totalRevenue: 8_940_000,
        rating: 4.6,
        verified: true,
      },
      {
        id: 'seller_3',
        name: '酒店管理咨询公司',
        avatar: '/images/sellers/seller-3.jpg',
        totalListings: 12,
        totalOrders: 67,
        totalRevenue: 6_780_000,
        rating: 4.7,
        verified: true,
      },
      {
        id: 'seller_4',
        name: '餐饮管理公司',
        avatar: '/images/sellers/seller-4.jpg',
        totalListings: 18,
        totalOrders: 45,
        totalRevenue: 3_240_000,
        rating: 4.4,
        verified: true,
      },
      {
        id: 'seller_5',
        name: '设备租赁公司',
        avatar: '/images/sellers/seller-5.jpg',
        totalListings: 25,
        totalOrders: 123,
        totalRevenue: 5_670_000,
        rating: 4.5,
        verified: false,
      },
    ],
    hotKeywords: [
      { keyword: '酒店', count: 234, trend: 'up' },
      { keyword: '管理系统', count: 189, trend: 'up' },
      { keyword: '餐厅', count: 156, trend: 'stable' },
      { keyword: '豪华', count: 134, trend: 'up' },
      { keyword: '团队', count: 98, trend: 'down' },
      { keyword: 'SaaS', count: 87, trend: 'up' },
      { keyword: '设备', count: 76, trend: 'stable' },
      { keyword: '咨询', count: 65, trend: 'down' },
    ],
    performance: {
      avgResponseTime: 1.2,
      successRate: 99.7,
      userSatisfaction: 4.6,
      systemUptime: 99.9,
    },
  };

  return {
    code: 0,
    data: stats,
    msg: '获取市场统计信息成功',
  };
});
